
# TABLE F19

CrossTable(PRRdataframe2$Ambitioncand, PRRdataframe2$Gender, prop.c=TRUE,
           prop.t=FALSE, prop.r=FALSE, prop.chisq = FALSE,
           total.r=TRUE, total.c=TRUE, chisq=TRUE)

# TABLE F20

CrossTable(PRRdataframe2$Futurepost, PRRdataframe2$Gender, prop.c=TRUE,
           prop.t=FALSE, prop.r=FALSE, prop.chisq = FALSE,
           total.r=TRUE, total.c=TRUE, chisq=TRUE)

# TABLE F21

CrossTable(PRRdataframe2$Leaving, PRRdataframe2$Gender, prop.c=TRUE,
           prop.t=FALSE, prop.r=FALSE, prop.chisq = FALSE,
           total.r=TRUE, total.c=TRUE, chisq=TRUE)

# TABLE F22

CrossTable(PRRdataframe2$Stigma, PRRdataframe2$Gender, prop.c=TRUE,
           prop.t=FALSE, prop.r=FALSE, prop.chisq = FALSE,
           total.r=TRUE, total.c=TRUE, chisq=TRUE)

# TABLE F23

CrossTable(PRRdataframe2$Socialization, PRRdataframe2$Gender, prop.c=TRUE,
           prop.t=FALSE, prop.r=FALSE, prop.chisq = FALSE,
           total.r=TRUE, total.c=TRUE, chisq=TRUE)

###======================================================###

### Address endogeneity between networks & activism

# Instrumental variable

library(AER)

first_stage <- glm(Newfriends ~ Personalties + Gender +
                     age + agesquared + Tertiaryedu + Labourforce + Policyinfluence + Ambitioncand + Party,
                   data = PRRdataframe2, weights = df_weights, family = "binomial")

second_stage <- lm(PCA_activism ~ predict(first_stage) + Gender +
                     age + agesquared + Tertiaryedu + Labourforce + Policyinfluence + Ambitioncand + Party,
                   data = PRRdataframe2, weights = df_weights)

model_2sls <- ivreg(PCA_activism ~ Newfriends + Gender +
                      age + agesquared + Tertiaryedu + Labourforce + Policyinfluence + Ambitioncand + Party |
                      Personalties + Gender +
                      age + agesquared + Tertiaryedu + Labourforce + Policyinfluence + Ambitioncand + Party,
                    data = PRRdataframe2, weights = df_weights)

summary(model_2sls, diagnostics = TRUE)

msummary(model_2sls, stars = TRUE, coef_rename = coefficientsnames)
msummary(model_2sls, stars = TRUE, coef_rename = coefficientsnames,
         output = "2SLS.docx")

# Old friends

meeting_0_friends <- lm(PCA_activism ~ Gender + Tertiaryedu + Labourforce +
                          Policyinfluence + Ambitioncand + Partyrecruitment + Stigma +
                          age + agesquared + yearsmember + Party,
                        data = PRRdataframe2, weights = df_weights)
modelsummary(meeting_0_friends, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)

meeting_M_friends <- glm(Personalties ~ Gender + Tertiaryedu + Labourforce +
                           Policyinfluence + Ambitioncand + Partyrecruitment + Stigma +
                           age + agesquared + yearsmember + Party,
                         data = PRRdataframe2, weights = df_weights, family = "binomial")
modelsummary(meeting_M_friends, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)
PseudoR2(meeting_M_friends)

meeting_Y_friends <- lm(PCA_activism ~ Gender + Personalties + Tertiaryedu + Labourforce +
                          Policyinfluence + Ambitioncand + Partyrecruitment + Stigma +
                          age + agesquared + yearsmember + Party,
                        data = PRRdataframe2, weights = df_weights)
modelsummary(meeting_Y_friends, stars = TRUE, vcov = ~Party, coef_rename = coefficientsnames)

set.seed(2024)

PCA_friends_results <- mediate(meeting_M_friends, meeting_Y_friends,
                               treat = "Gender", mediator = "Personalties",
                               sims = 1000)

summary(PCA_friends_results)



